require 'sinatra/base'

require './handlers/base'
require './models/user'
require './helpers/auth'

class UserHandler < BaseHandler
    ## USER ROUTES
    
    get '/users/:id' do
        @r = Response.new("This user doesn't exist!").to_json
        u = User.first(:id=>Integer(params[:id]))
        if not u.nil?
            @r = Response.new(nil, u).to_json
        end
        
    end

    put '/users/:id' do
        u = User.first(:id=>Integer(params[:id]))
        if current_user == u and not @data.nil?
            u.update(@data)
        end
    end
end